const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    mode:'development',
    entry:{
        index:path.resolve(__dirname,'./src/js/index.js')
    },
    output:{
        path:path.resolve(__dirname,'dist'),
        filename: "js/[name].js"
    },
    module:{
        rules:[{
            test:/\.js$/,
            loader: 'babel-loader',
            exclude: path.resolve(__dirname,'node_modules'),
            options: {
                presets:['env']
            }
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            minify:{
                removeComments:true,  	 //去除所有的注释
                collapseWhitespace:true  //去除所有空格
            },
            filename:'index.html',    	//指定生成的文件的名称，该文件存在于内存中，在目录中不显示
            template: path.resolve(__dirname,'src/index.html'),   //指定要用到的模板文件
            files:{   					 //这个页面包含哪些文件
                js:['js/index.js'],
                    chunks:{
                    'main':{
                        'entry':'dist/bundle.js'
                    }
                }
            },
            excludeChunks:['node_modules']   /*排除*/
        })
    ],
    devServer:{
        contentBase:"./",
        open:true,
        host:"localhost",
        port:"8888"
    }
};
